#include	<stdio.h>
#include	<stdio.h>
#include	<stdlib.h>
#include	<string.h>
#include	<algorithm>

typedef struct sultion_s
{
    int typecount;
    int stampcount;
    int highvalue;
}solution_t;

bool hasSolution = false;
bool tied = false;

static solution_t  bestSolution;
static solution_t  currSolution;

static int seqArrLen = 0;

static int solutionArr[64];
static int currSolutionArr[64];

int cmpSolution(const solution_t* p1, const solution_t *p2)
{
    if (p1->typecount > p2->typecount)
        return 1;
    else if (p1->typecount == p2->typecount)
    {
        if (p1->stampcount < p2->stampcount)
            return 1;
        else if (p1->stampcount == p2->stampcount)
        {
            if (p1->highvalue == p2->highvalue)
                return 0;
            else if (p1->highvalue > p2->highvalue)
                return 1;
            else 
                return -1;
        }
        else 
            return -1;
    }
    else 
        return -1;

}

/* use brute force first */
void searchSolution(int *seqArr, int idx, int need)
{
    if (need == 0)
    {
//        printf ( ">>>find a solution with typecount:%d, stampcount:%d, highvalue:%d<<<\n", 
//                currSolution.typecount, currSolution.stampcount, currSolution.highvalue);
//        for (int k = 0; k < seqArrLen; ++k)
//        {
//            for (int g = 0; g < currSolutionArr[k]; ++g)
//                printf ( "(%d,%d)", k, seqArr[k]);
//        }
//        printf ( "\n" );
        if (!hasSolution)
        {
            hasSolution = true;
            bestSolution = currSolution;
            memcpy(solutionArr, currSolutionArr, sizeof(solutionArr));
            tied = false;
        }
        else 
        {
            if (cmpSolution(&bestSolution, &currSolution) < 0) {
                bestSolution = currSolution;
                memcpy(solutionArr, currSolutionArr, sizeof(solutionArr));
                tied = false;
            }
            else if (cmpSolution(&bestSolution, &currSolution) == 0) {
                tied = true;
            }
        }
        return;
    }
    if (idx >= seqArrLen)
        return;

    currSolutionArr[idx] = 0;
    searchSolution(seqArr, idx+1, need);

    currSolution.typecount += 1;
    int bakhighvalue = currSolution.highvalue;
    if (seqArr[idx] > currSolution.highvalue);
        currSolution.highvalue = seqArr[idx];
    for (int i = 1; i <= 4; ++i)
    {
        if ((i * seqArr[idx] > need) || (i + currSolution.stampcount) > 4)
            break;
        currSolution.stampcount += i;
        currSolutionArr[idx] = i;
        searchSolution(seqArr, idx+1, need-(i * seqArr[idx]));
        currSolution.stampcount -= i;
    }
    currSolution.highvalue = bakhighvalue;
    currSolution.typecount -= 1;
    currSolutionArr[idx] = 0;
}


static int seqArr[64];
int main(int argc, char *argv[])
{
    int value;
    int idx = 0;
    while (scanf("%d", &value) == 1)
    {
        if (value != 0)
        {
            seqArr[idx++] = value;
        }
        else 
        {
            seqArrLen = idx;
            currSolution.highvalue = 0;
            currSolution.stampcount = 0;
            currSolution.typecount = 0;
            memset(currSolutionArr, 0x00, sizeof(currSolutionArr));
            std::sort(seqArr, seqArr+seqArrLen);

            while (scanf("%d", &value) == 1 && value != 0)
            {
                hasSolution = false;
                tied = false;

                searchSolution(seqArr, 0, value);

                if (hasSolution == false) {
                    printf ( "%d ---- none\n", value );
                } else if (tied) {
                    printf ( "%d (%d): tie\n", value, bestSolution.typecount);
                } else {
                    printf ( "%d (%d):", value, bestSolution.typecount);
                    for (int k = 0; k < seqArrLen; ++k)
                    {
                        for (int g = 0; g < solutionArr[k]; ++g)
                            printf ( " %d", seqArr[k]);
                    }
                    printf ( "\n" );
                }
            }
            idx = 0;
        } //else 
    }
    return 0;
}
